<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  <title>Redis系列一之入门 | Hexo</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="description" content="概述　　redis是一个key-value存储系统。和Memcached类似，它支持存储的value类型相对更多，包括string(字符串)、list(链表)、set(集合)、zset(sorted set –有序集合)和hash（哈希类型）。这些数据类型都支持push/pop、add/remove及取交集并集和差集及更丰富的操作，而且这些操作都是原子性的。在此基础上，redis支持各种不同方式的">
<meta property="og:type" content="article">
<meta property="og:title" content="Redis系列一之入门">
<meta property="og:url" content="http://yoursite.com/2015/12/11/redis/1.Redis系列之入门/index.html">
<meta property="og:site_name" content="Hexo">
<meta property="og:description" content="概述　　redis是一个key-value存储系统。和Memcached类似，它支持存储的value类型相对更多，包括string(字符串)、list(链表)、set(集合)、zset(sorted set –有序集合)和hash（哈希类型）。这些数据类型都支持push/pop、add/remove及取交集并集和差集及更丰富的操作，而且这些操作都是原子性的。在此基础上，redis支持各种不同方式的">
<meta property="og:updated_time" content="2016-01-29T17:47:36.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Redis系列一之入门">
<meta name="twitter:description" content="概述　　redis是一个key-value存储系统。和Memcached类似，它支持存储的value类型相对更多，包括string(字符串)、list(链表)、set(集合)、zset(sorted set –有序集合)和hash（哈希类型）。这些数据类型都支持push/pop、add/remove及取交集并集和差集及更丰富的操作，而且这些操作都是原子性的。在此基础上，redis支持各种不同方式的">
  
    <link rel="alternative" href="/atom.xml" title="Hexo" type="application/atom+xml">
  
  
    <link rel="icon" href="/favicon.png">
  
  <link href="//fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
  <link rel="stylesheet" href="/css/style.css" type="text/css">
  

</head>
<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/" id="logo">Hexo</a>
      </h1>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"></a>
        
          <a class="main-nav-link" href="/">Home</a>
        
          <a class="main-nav-link" href="/archives">Archives</a>
        
      </nav>
      <nav id="sub-nav">
        
          <a id="nav-rss-link" class="nav-icon" href="/atom.xml" title="RSS Feed"></a>
        
        <a id="nav-search-btn" class="nav-icon" title="Search"></a>
      </nav>
      <div id="search-form-wrap">
        <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" results="0" class="search-form-input" placeholder="Search"><button type="submit" class="search-form-submit">&#xF002;</button><input type="hidden" name="sitesearch" value="http://yoursite.com"></form>
      </div>
    </div>
  </div>
</header>
      <div class="outer">
        <section id="main"><article id="post-redis/1.Redis系列之入门" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2015/12/11/redis/1.Redis系列之入门/" class="article-date">
  <time datetime="2015-12-11T04:00:00.000Z" itemprop="datePublished">2015-12-11</time>
</a>
    
  <div class="article-category">
    <a class="article-category-link" href="/categories/redis/">redis</a>
  </div>

  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="article-title" itemprop="name">
      Redis系列一之入门
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <h2 id="u6982_u8FF0"><a href="#u6982_u8FF0" class="headerlink" title="概述"></a>概述</h2><p>　　redis是一个key-value存储系统。和Memcached类似，它支持存储的value类型相对更多，包括string(字符串)、list(链表)、set(集合)、zset(sorted set –有序集合)和hash（哈希类型）。这些数据类型都支持push/pop、add/remove及取交集并集和差集及更丰富的操作，而且这些操作都是原子性的。在此基础上，redis支持各种不同方式的排序。与memcached一样，为了保证效率，数据都是缓存在内存中。区别的是redis会周期性的把更新的数据写入磁盘或者把修改操作写入追加的记录文件，并且在此基础上实现了master-slave(主从)同步。<br>　　本篇文章将介绍redis在单个centos下的编译安装与配置，包括单节点配置、master-slave配置、shard配置（其实就是单节点配置，只是端口和db路径不同罢了）。在下一篇文章中，我们将采用java的jedis客户端进行连接、测试，验证配置的有效性！</p>
<h2 id="u7F16_u8BD1_u5B89_u88C5"><a href="#u7F16_u8BD1_u5B89_u88C5" class="headerlink" title="编译安装"></a>编译安装</h2><p>　　通过如下命令即可在centos下安装redis。<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">wget http://download.redis.io/releases/redis-<span class="number">2.8</span>.<span class="number">19</span>.tar.gz</span><br><span class="line">tar xzf redis-<span class="number">2.8</span>.<span class="number">19</span>.tar.gz</span><br><span class="line">mv redis-<span class="number">2.8</span>.<span class="number">19</span>.tar.gz redis</span><br><span class="line"><span class="built_in">cd</span> redis</span><br><span class="line">make</span><br></pre></td></tr></table></figure></p>
<p>　　编译完成后，在src目录下，有五个可执行文件redis-server、redis-benchmark、redis-cli、redis-check-dump、redis-check-aof和redis-sentinel。将他们拷贝到redis/bin目录下即可（需要在redis下新建bin目录）。同时将redis目录下的redis.conf和sentinel.conf文件拷贝到redis/bin目录下</p>
<h2 id="redis_u914D_u7F6E_u89C4_u5212"><a href="#redis_u914D_u7F6E_u89C4_u5212" class="headerlink" title="redis配置规划"></a>redis配置规划</h2><p>　　在此次安装中，我们将在单机模式下进行master-slaver和sentinel模式的配置，服务器内网地址为：192.168.85.64。下表记录了配置的目录和端口等信息。</p>
<table>
<thead>
<tr>
<th style="text-align:left">节点类型</th>
<th style="text-align:left">端口</th>
<th style="text-align:left">配置文件</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">master</td>
<td style="text-align:left">6379</td>
<td style="text-align:left">redis/bin/conf/redis-master-6379.conf</td>
</tr>
<tr>
<td style="text-align:left">slaver1</td>
<td style="text-align:left">6380</td>
<td style="text-align:left">redis/bin/conf/redis-slave1-6380.conf</td>
</tr>
<tr>
<td style="text-align:left">slaver2</td>
<td style="text-align:left">6381</td>
<td style="text-align:left">redis/bin/conf/redis-slave2-6381.conf</td>
</tr>
<tr>
<td style="text-align:left">slaver3</td>
<td style="text-align:left">6382</td>
<td style="text-align:left">redis/bin/conf/redis-slave3-6382.conf</td>
</tr>
<tr>
<td style="text-align:left">sentinel1</td>
<td style="text-align:left">26379</td>
<td style="text-align:left">redis/bin/conf/sentinel-26379.conf</td>
</tr>
<tr>
<td style="text-align:left">sentinel2</td>
<td style="text-align:left">26479</td>
<td style="text-align:left">redis/bin/conf/sentinel-26479.conf</td>
</tr>
<tr>
<td style="text-align:left">sentinel3</td>
<td style="text-align:left">26579</td>
<td style="text-align:left">redis/bin/conf/sentinel-26579.conf</td>
</tr>
</tbody>
</table>
<h2 id="master_u914D_u7F6E"><a href="#master_u914D_u7F6E" class="headerlink" title="master配置"></a>master配置</h2><p>　　master配置文件：redis-master-6379.conf。实际上只是调整了redis.conf配置文件的几个默认属性：daemonize、pidfile、logfile、dbfilename、dir等<br><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br></pre></td><td class="code"><pre><span class="line">daemonize yes</span><br><span class="line">pidfile ./run/redis_master_6379.pid</span><br><span class="line">port 6379</span><br><span class="line">tcp-backlog 511</span><br><span class="line">timeout 0</span><br><span class="line">tcp-keepalive 0</span><br><span class="line">loglevel notice</span><br><span class="line">logfile "./logs/master_6379.log"</span><br><span class="line">databases 16</span><br><span class="line"></span><br><span class="line">save ""</span><br><span class="line"><span class="operator"><span class="keyword">stop</span>-writes-<span class="keyword">on</span>-bgsave-<span class="keyword">error</span> yes</span><br><span class="line">rdbcompression yes</span><br><span class="line">rdbchecksum yes</span><br><span class="line">dbfilename dump_master_6379.rdb</span><br><span class="line">dir ./db</span><br><span class="line"></span><br><span class="line"><span class="keyword">slave</span>-serve-stale-<span class="keyword">data</span> yes</span><br><span class="line"><span class="keyword">slave</span>-<span class="keyword">read</span>-<span class="keyword">only</span> yes</span><br><span class="line">repl-diskless-<span class="keyword">sync</span> <span class="keyword">no</span></span><br><span class="line">repl-diskless-<span class="keyword">sync</span>-delay <span class="number">5</span></span><br><span class="line">repl-<span class="keyword">disable</span>-tcp-<span class="keyword">nodelay</span> <span class="keyword">no</span></span><br><span class="line"><span class="keyword">slave</span>-<span class="keyword">priority</span> <span class="number">100</span></span><br><span class="line"></span><br><span class="line">appendonly <span class="keyword">no</span></span><br><span class="line">appendfilename <span class="string">"appendonly_master_6379.aof"</span></span><br><span class="line">appendfsync <span class="keyword">no</span></span><br><span class="line"><span class="keyword">no</span>-appendfsync-<span class="keyword">on</span>-rewrite <span class="keyword">no</span></span><br><span class="line"><span class="keyword">auto</span>-aof-rewrite-percentage <span class="number">100</span></span><br><span class="line"><span class="keyword">auto</span>-aof-rewrite-<span class="keyword">min</span>-<span class="keyword">size</span> <span class="number">64</span>mb</span><br><span class="line">aof-<span class="keyword">load</span>-truncated yes</span><br><span class="line"></span><br><span class="line">lua-<span class="keyword">time</span>-<span class="keyword">limit</span> <span class="number">5000</span></span><br><span class="line"></span><br><span class="line">slowlog-<span class="keyword">log</span>-slower-<span class="keyword">than</span> <span class="number">10000</span></span><br><span class="line">slowlog-<span class="keyword">max</span>-<span class="keyword">len</span> <span class="number">128</span></span><br><span class="line"></span><br><span class="line">latency-monitor-threshold <span class="number">0</span></span><br><span class="line"></span><br><span class="line">notify-keyspace-<span class="keyword">events</span> <span class="string">""</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">hash</span>-<span class="keyword">max</span>-ziplist-entries <span class="number">512</span></span><br><span class="line"><span class="keyword">hash</span>-<span class="keyword">max</span>-ziplist-<span class="keyword">value</span> <span class="number">64</span></span><br><span class="line"><span class="keyword">list</span>-<span class="keyword">max</span>-ziplist-entries <span class="number">512</span></span><br><span class="line"><span class="keyword">list</span>-<span class="keyword">max</span>-ziplist-<span class="keyword">value</span> <span class="number">64</span></span><br><span class="line"><span class="keyword">set</span>-<span class="keyword">max</span>-intset-entries <span class="number">512</span></span><br><span class="line">zset-<span class="keyword">max</span>-ziplist-entries <span class="number">128</span></span><br><span class="line">zset-<span class="keyword">max</span>-ziplist-<span class="keyword">value</span> <span class="number">64</span></span><br><span class="line">hll-<span class="keyword">sparse</span>-<span class="keyword">max</span>-<span class="keyword">bytes</span> <span class="number">3000</span></span><br><span class="line">activerehashing yes</span><br><span class="line"><span class="keyword">client</span>-<span class="keyword">output</span>-buffer-<span class="keyword">limit</span> <span class="keyword">normal</span> <span class="number">0</span> <span class="number">0</span> <span class="number">0</span></span><br><span class="line"><span class="keyword">client</span>-<span class="keyword">output</span>-buffer-<span class="keyword">limit</span> <span class="keyword">slave</span> <span class="number">256</span>mb <span class="number">64</span>mb <span class="number">60</span></span><br><span class="line"><span class="keyword">client</span>-<span class="keyword">output</span>-buffer-<span class="keyword">limit</span> pubsub <span class="number">32</span>mb <span class="number">8</span>mb <span class="number">60</span></span><br><span class="line">hz <span class="number">10</span></span><br><span class="line">aof-rewrite-incremental-fsync yes</span></span><br></pre></td></tr></table></figure></p>
<h2 id="slaver_u914D_u7F6E"><a href="#slaver_u914D_u7F6E" class="headerlink" title="slaver配置"></a>slaver配置</h2><p>　　slaver配置文件：redis-slave1-6380.conf。实际上只是调整了redis.conf配置文件的几个默认属性：daemonize、pidfile、port、logfile、dbfilename、dir，同时制定了slaveof属性。另外两个salver配置文件redis-slave2-6381.conf和redis-slave3-6382.conf只需要修改slaver1的配置pidfile、port、logfile、dbfilename、appendfilename即可。注意，由于是运行在同一个机器上，各个属性值不能相同<br><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br></pre></td><td class="code"><pre><span class="line">daemonize yes</span><br><span class="line">pidfile "./run/redis_slave1_6380.pid"</span><br><span class="line">port 6380</span><br><span class="line">tcp-backlog 511</span><br><span class="line">timeout 0</span><br><span class="line">tcp-keepalive 0</span><br><span class="line">loglevel notice</span><br><span class="line">logfile "./logs/slave1_6380.log"</span><br><span class="line">databases 16</span><br><span class="line"></span><br><span class="line"><span class="operator"><span class="keyword">stop</span>-writes-<span class="keyword">on</span>-bgsave-<span class="keyword">error</span> yes</span><br><span class="line">rdbcompression yes</span><br><span class="line">rdbchecksum <span class="keyword">no</span></span><br><span class="line">dbfilename <span class="string">"dump_slave1_6380.rdb"</span></span><br><span class="line">dir <span class="string">"/mapbar/redis/redis/bin/db"</span></span><br><span class="line"></span><br><span class="line">slaveof <span class="number">192.168</span><span class="number">.85</span><span class="number">.64</span> <span class="number">6379</span></span><br><span class="line"><span class="keyword">slave</span>-serve-stale-<span class="keyword">data</span> yes</span><br><span class="line"><span class="keyword">slave</span>-<span class="keyword">read</span>-<span class="keyword">only</span> yes</span><br><span class="line">repl-diskless-<span class="keyword">sync</span> <span class="keyword">no</span></span><br><span class="line">repl-diskless-<span class="keyword">sync</span>-delay <span class="number">5</span></span><br><span class="line">repl-<span class="keyword">disable</span>-tcp-<span class="keyword">nodelay</span> <span class="keyword">no</span></span><br><span class="line"><span class="keyword">slave</span>-<span class="keyword">priority</span> <span class="number">80</span></span><br><span class="line"></span><br><span class="line">appendonly <span class="keyword">no</span></span><br><span class="line">appendfilename <span class="string">"appendonly_slave1_6380.aof"</span></span><br><span class="line">appendfsync <span class="keyword">no</span></span><br><span class="line"><span class="keyword">no</span>-appendfsync-<span class="keyword">on</span>-rewrite <span class="keyword">no</span></span><br><span class="line"><span class="keyword">auto</span>-aof-rewrite-percentage <span class="number">100</span></span><br><span class="line"><span class="keyword">auto</span>-aof-rewrite-<span class="keyword">min</span>-<span class="keyword">size</span> <span class="number">64</span>mb</span><br><span class="line">aof-<span class="keyword">load</span>-truncated yes</span><br><span class="line"></span><br><span class="line">lua-<span class="keyword">time</span>-<span class="keyword">limit</span> <span class="number">5000</span></span><br><span class="line"></span><br><span class="line">slowlog-<span class="keyword">log</span>-slower-<span class="keyword">than</span> <span class="number">10000</span></span><br><span class="line">slowlog-<span class="keyword">max</span>-<span class="keyword">len</span> <span class="number">128</span></span><br><span class="line"></span><br><span class="line">latency-monitor-threshold <span class="number">0</span></span><br><span class="line"></span><br><span class="line">notify-keyspace-<span class="keyword">events</span> <span class="string">""</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">hash</span>-<span class="keyword">max</span>-ziplist-entries <span class="number">512</span></span><br><span class="line"><span class="keyword">hash</span>-<span class="keyword">max</span>-ziplist-<span class="keyword">value</span> <span class="number">64</span></span><br><span class="line"><span class="keyword">list</span>-<span class="keyword">max</span>-ziplist-entries <span class="number">512</span></span><br><span class="line"><span class="keyword">list</span>-<span class="keyword">max</span>-ziplist-<span class="keyword">value</span> <span class="number">64</span></span><br><span class="line"><span class="keyword">set</span>-<span class="keyword">max</span>-intset-entries <span class="number">512</span></span><br><span class="line">zset-<span class="keyword">max</span>-ziplist-entries <span class="number">128</span></span><br><span class="line">zset-<span class="keyword">max</span>-ziplist-<span class="keyword">value</span> <span class="number">64</span></span><br><span class="line">hll-<span class="keyword">sparse</span>-<span class="keyword">max</span>-<span class="keyword">bytes</span> <span class="number">3000</span></span><br><span class="line">activerehashing yes</span><br><span class="line"><span class="keyword">client</span>-<span class="keyword">output</span>-buffer-<span class="keyword">limit</span> <span class="keyword">normal</span> <span class="number">0</span> <span class="number">0</span> <span class="number">0</span></span><br><span class="line"><span class="keyword">client</span>-<span class="keyword">output</span>-buffer-<span class="keyword">limit</span> <span class="keyword">slave</span> <span class="number">256</span>mb <span class="number">64</span>mb <span class="number">60</span></span><br><span class="line"><span class="keyword">client</span>-<span class="keyword">output</span>-buffer-<span class="keyword">limit</span> pubsub <span class="number">32</span>mb <span class="number">8</span>mb <span class="number">60</span></span><br><span class="line">hz <span class="number">10</span></span><br><span class="line">aof-rewrite-incremental-fsync yes</span></span><br></pre></td></tr></table></figure></p>
<h2 id="sentinel_u914D_u7F6E"><a href="#sentinel_u914D_u7F6E" class="headerlink" title="sentinel配置"></a>sentinel配置</h2><p>　　sentinel1节点配置文件为：sentinel-26379.conf，输入如下内容<br><figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">port <span class="number">26379</span></span><br><span class="line">dir <span class="string">"./db/26379"</span></span><br><span class="line">sentinel monitor master1 <span class="number">192.168</span><span class="number">.85</span><span class="number">.64</span> <span class="number">6379</span> <span class="number">2</span></span><br><span class="line">sentinel down-after-milliseconds master1 <span class="number">30000</span></span><br><span class="line">sentinel parallel-syncs master1 <span class="number">1</span></span><br><span class="line">sentinel failover-timeout master1 <span class="number">180000</span></span><br><span class="line">logfile <span class="string">"/tmp/sentinellog__26379.log"</span></span><br></pre></td></tr></table></figure></p>
<p>　　sentinel2节点配置文件为：sentinel-26479.conf，输入如下内容<br><figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">port <span class="number">26479</span></span><br><span class="line">dir <span class="string">"./db/26479"</span></span><br><span class="line">sentinel monitor master1 <span class="number">192.168</span><span class="number">.85</span><span class="number">.64</span> <span class="number">6379</span> <span class="number">2</span></span><br><span class="line">sentinel down-after-milliseconds master1 <span class="number">30000</span></span><br><span class="line">sentinel parallel-syncs master1 <span class="number">1</span></span><br><span class="line">sentinel failover-timeout master1 <span class="number">180000</span></span><br><span class="line">logfile <span class="string">"/tmp/sentinellog__26479.log"</span></span><br></pre></td></tr></table></figure></p>
<p>　　sentinel3节点配置文件为：sentinel-26579.conf，输入如下内容<br><figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">port <span class="number">26579</span></span><br><span class="line">dir <span class="string">"./db/26579"</span></span><br><span class="line">sentinel monitor master1 <span class="number">192.168</span><span class="number">.85</span><span class="number">.64</span> <span class="number">6379</span> <span class="number">2</span></span><br><span class="line">sentinel down-after-milliseconds master1 <span class="number">30000</span></span><br><span class="line">sentinel parallel-syncs master1 <span class="number">1</span></span><br><span class="line">sentinel failover-timeout master1 <span class="number">180000</span></span><br><span class="line">logfile <span class="string">"/tmp/sentinellog__26579.log"</span></span><br></pre></td></tr></table></figure></p>
<h2 id="u542F_u52A8_u670D_u52A1"><a href="#u542F_u52A8_u670D_u52A1" class="headerlink" title="启动服务"></a>启动服务</h2><p>master节点<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">./redis-server ./conf/redis-master-<span class="number">6379</span>.conf &amp;</span><br></pre></td></tr></table></figure></p>
<p>slaver1节点<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">./redis-server ./conf/redis-slave1-<span class="number">6380</span>.conf &amp;</span><br></pre></td></tr></table></figure></p>
<p>slaver2节点<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">./redis-server ./conf/redis-slave2-<span class="number">6381</span>.conf &amp;</span><br></pre></td></tr></table></figure></p>
<p>slaver3节点<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">./redis-server ./conf/redis-slave3-<span class="number">6382</span>.conf &amp;</span><br></pre></td></tr></table></figure></p>
<p>sentinel1节点<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">./redis-sentinel ./conf/sentinel-<span class="number">26379</span>.conf &amp;</span><br></pre></td></tr></table></figure></p>
<p>sentinel2节<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">./redis-sentinel ./conf/sentinel-<span class="number">26479</span>.conf &amp;</span><br></pre></td></tr></table></figure></p>
<p>sentinel3节点<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">./redis-sentinel ./conf/sentinel-<span class="number">26579</span>.conf &amp;</span><br></pre></td></tr></table></figure></p>
<h2 id="u5173_u95ED_u670D_u52A1"><a href="#u5173_u95ED_u670D_u52A1" class="headerlink" title="关闭服务"></a>关闭服务</h2><p>　　redis-cli shutdown 或者直接在启动服务的端口中直接Ctrl+C。如果不是默认的端口，则需要指定端口号：redis-cli -p 6382 shutdown</p>
<p>　　到这里配置完成了，下一篇文章我们将通过java客户端验证配置的正确性。注意，在实际使用的过程中，会发现如果服务器宕机，由于配置sentinel，此时会自动从slave中选取一个master。这样会导致原配置文件发生变化，切记！！！完整的配置文件如下：待补充</p>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://yoursite.com/2015/12/11/redis/1.Redis系列之入门/" data-id="cijzzpv6700451cfsnrnx0nvn" class="article-share-link">Share</a>
      
      
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/redis/">redis</a></li></ul>

    </footer>
  </div>
  
    
<nav id="article-nav">
  
    <a href="/2015/12/11/redis/2.Redis系列之Java客户端/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Newer</strong>
      <div class="article-nav-title">
        
          Redis系列二之Java客户端
        
      </div>
    </a>
  
  
    <a href="/2015/12/09/mybatis/9.Mybatis系列之负载均衡与读写分离/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Older</strong>
      <div class="article-nav-title">Mybatis系列九之负载均衡与读写分析</div>
    </a>
  
</nav>

  
</article>

</section>
        
          <aside id="sidebar">
  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Categories</h3>
    <div class="widget">
      <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/categories/cache/">cache</a><span class="category-list-count">3</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/database/">database</a><span class="category-list-count">13</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/docker/">docker</a><span class="category-list-count">6</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/gis/">gis</a><span class="category-list-count">4</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/git/">git</a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/go/">go</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/gradle/">gradle</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/groovy/">groovy</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/hadoop/">hadoop</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/java/">java</a><span class="category-list-count">18</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/linux/">linux</a><span class="category-list-count">4</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/log/">log</a><span class="category-list-count">11</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/mongodb/">mongodb</a><span class="category-list-count">14</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/mq/">mq</a><span class="category-list-count">6</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/mybatis/">mybatis</a><span class="category-list-count">9</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/netty/">netty</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/nginx/">nginx</a><span class="category-list-count">3</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/nio/">nio</a><span class="category-list-count">19</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/nodejs/">nodejs</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/redis/">redis</a><span class="category-list-count">6</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/rpc/">rpc</a><span class="category-list-count">14</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/spring/">spring</a><span class="category-list-count">5</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/tomcat/">tomcat</a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/zookeeper/">zookeeper</a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/杂项/">杂项</a><span class="category-list-count">2</span></li></ul>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tags</h3>
    <div class="widget">
      <ul class="tag-list"><li class="tag-list-item"><a class="tag-list-link" href="/tags/aop/">aop</a><span class="tag-list-count">8</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/aspectj/">aspectj</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/cache/">cache</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/classloader/">classloader</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/common-loggings/">common-loggings</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/commonjs/">commonjs</a><span class="tag-list-count">4</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/database/">database</a><span class="tag-list-count">10</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/docker/">docker</a><span class="tag-list-count">6</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/dubbo/">dubbo</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/fastdfs/">fastdfs</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/gclib/">gclib</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/geohash/">geohash</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/gis/">gis</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/git/">git</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/go/">go</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/gradle/">gradle</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/groovy/">groovy</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/hadoop/">hadoop</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/hessisan/">hessisan</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/java/">java</a><span class="tag-list-count">48</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/javassist/">javassist</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/kafka/">kafka</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/linux/">linux</a><span class="tag-list-count">4</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/log/">log</a><span class="tag-list-count">11</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/log4j/">log4j</a><span class="tag-list-count">4</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/logback/">logback</a><span class="tag-list-count">5</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/map/">map</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/memecached/">memecached</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/mina/">mina</a><span class="tag-list-count">5</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/mongodb/">mongodb</a><span class="tag-list-count">14</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/mq/">mq</a><span class="tag-list-count">6</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/mqtt/">mqtt</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/mybatis/">mybatis</a><span class="tag-list-count">9</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/netty/">netty</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/nginx/">nginx</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/nio/">nio</a><span class="tag-list-count">5</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/nodejs/">nodejs</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/postgresql/">postgresql</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/protobuf/">protobuf</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/proxy/">proxy</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/push/">push</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/rabbitmq/">rabbitmq</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/redis/">redis</a><span class="tag-list-count">6</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/rpc/">rpc</a><span class="tag-list-count">14</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/sitemesh/">sitemesh</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/sld/">sld</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/slf4j/">slf4j</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/socket/">socket</a><span class="tag-list-count">7</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/spatialite-for-android/">spatialite for android</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/spi/">spi</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/spring/">spring</a><span class="tag-list-count">13</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/tomcat/">tomcat</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/transaction/">transaction</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/web/">web</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/xSocket/">xSocket</a><span class="tag-list-count">7</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/zbus/">zbus</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/zookeeper/">zookeeper</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/数据结构/">数据结构</a><span class="tag-list-count">2</span></li></ul>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tag Cloud</h3>
    <div class="widget tagcloud">
      <a href="/tags/aop/" style="font-size: 15.38px;">aop</a> <a href="/tags/aspectj/" style="font-size: 11.54px;">aspectj</a> <a href="/tags/cache/" style="font-size: 11.54px;">cache</a> <a href="/tags/classloader/" style="font-size: 10px;">classloader</a> <a href="/tags/common-loggings/" style="font-size: 10px;">common-loggings</a> <a href="/tags/commonjs/" style="font-size: 12.31px;">commonjs</a> <a href="/tags/database/" style="font-size: 16.92px;">database</a> <a href="/tags/docker/" style="font-size: 13.85px;">docker</a> <a href="/tags/dubbo/" style="font-size: 10px;">dubbo</a> <a href="/tags/fastdfs/" style="font-size: 10px;">fastdfs</a> <a href="/tags/gclib/" style="font-size: 10.77px;">gclib</a> <a href="/tags/geohash/" style="font-size: 10px;">geohash</a> <a href="/tags/gis/" style="font-size: 10px;">gis</a> <a href="/tags/git/" style="font-size: 10.77px;">git</a> <a href="/tags/go/" style="font-size: 10px;">go</a> <a href="/tags/gradle/" style="font-size: 10px;">gradle</a> <a href="/tags/groovy/" style="font-size: 10px;">groovy</a> <a href="/tags/hadoop/" style="font-size: 10px;">hadoop</a> <a href="/tags/hessisan/" style="font-size: 11.54px;">hessisan</a> <a href="/tags/java/" style="font-size: 20px;">java</a> <a href="/tags/javassist/" style="font-size: 10px;">javassist</a> <a href="/tags/kafka/" style="font-size: 11.54px;">kafka</a> <a href="/tags/linux/" style="font-size: 12.31px;">linux</a> <a href="/tags/log/" style="font-size: 17.69px;">log</a> <a href="/tags/log4j/" style="font-size: 12.31px;">log4j</a> <a href="/tags/logback/" style="font-size: 13.08px;">logback</a> <a href="/tags/map/" style="font-size: 10px;">map</a> <a href="/tags/memecached/" style="font-size: 10.77px;">memecached</a> <a href="/tags/mina/" style="font-size: 13.08px;">mina</a> <a href="/tags/mongodb/" style="font-size: 19.23px;">mongodb</a> <a href="/tags/mq/" style="font-size: 13.85px;">mq</a> <a href="/tags/mqtt/" style="font-size: 10.77px;">mqtt</a> <a href="/tags/mybatis/" style="font-size: 16.15px;">mybatis</a> <a href="/tags/netty/" style="font-size: 10px;">netty</a> <a href="/tags/nginx/" style="font-size: 11.54px;">nginx</a> <a href="/tags/nio/" style="font-size: 13.08px;">nio</a> <a href="/tags/nodejs/" style="font-size: 10px;">nodejs</a> <a href="/tags/postgresql/" style="font-size: 10.77px;">postgresql</a> <a href="/tags/protobuf/" style="font-size: 10px;">protobuf</a> <a href="/tags/proxy/" style="font-size: 10px;">proxy</a> <a href="/tags/push/" style="font-size: 10px;">push</a> <a href="/tags/rabbitmq/" style="font-size: 11.54px;">rabbitmq</a> <a href="/tags/redis/" style="font-size: 13.85px;">redis</a> <a href="/tags/rpc/" style="font-size: 19.23px;">rpc</a> <a href="/tags/sitemesh/" style="font-size: 10px;">sitemesh</a> <a href="/tags/sld/" style="font-size: 10px;">sld</a> <a href="/tags/slf4j/" style="font-size: 10px;">slf4j</a> <a href="/tags/socket/" style="font-size: 14.62px;">socket</a> <a href="/tags/spatialite-for-android/" style="font-size: 10px;">spatialite for android</a> <a href="/tags/spi/" style="font-size: 10px;">spi</a> <a href="/tags/spring/" style="font-size: 18.46px;">spring</a> <a href="/tags/tomcat/" style="font-size: 10.77px;">tomcat</a> <a href="/tags/transaction/" style="font-size: 10px;">transaction</a> <a href="/tags/web/" style="font-size: 10px;">web</a> <a href="/tags/xSocket/" style="font-size: 14.62px;">xSocket</a> <a href="/tags/zbus/" style="font-size: 10px;">zbus</a> <a href="/tags/zookeeper/" style="font-size: 10.77px;">zookeeper</a> <a href="/tags/数据结构/" style="font-size: 10.77px;">数据结构</a>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Archives</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/01/">January 2016</a><span class="archive-list-count">67</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/12/">December 2015</a><span class="archive-list-count">81</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/11/">November 2015</a><span class="archive-list-count">2</span></li></ul>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Recents</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/2016/01/30/资料/">(no title)</a>
          </li>
        
          <li>
            <a href="/2016/01/30/java/13.Classloader系列一/">ClassLoader系列一</a>
          </li>
        
          <li>
            <a href="/2016/01/29/hadoop/1.hadoop系列之源码编译/">hadoop系列一之源码编译</a>
          </li>
        
          <li>
            <a href="/2016/01/29/go/1.GO系列之入门/">Go系列一之入门</a>
          </li>
        
          <li>
            <a href="/2016/01/28/tomcat/2.tomcat性能优化/">tomcat性能优化</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      &copy; 2016 John Doe<br>
      Powered by <a href="http://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer>
    </div>
    <nav id="mobile-nav">
  
    <a href="/" class="mobile-nav-link">Home</a>
  
    <a href="/archives" class="mobile-nav-link">Archives</a>
  
</nav>
    


<script src="http://libs.baidu.com/jquery/2.0.3/jquery.min.js"></script>


  <link rel="stylesheet" href="/fancybox/jquery.fancybox.css" type="text/css">
  <script src="/fancybox/jquery.fancybox.pack.js" type="text/javascript"></script>


<script src="/js/script.js" type="text/javascript"></script>

  </div>
</body>
</html>